package com.evamay.kotlindemo.ui.viewpager

import android.content.Context
import android.graphics.Color
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.evamay.kotlindemo.R
import java.util.ArrayList

class PagerAdapter(val context: Context):RecyclerView.Adapter<PagerAdapter.PagerViewHolder>() {
    var list: ArrayList<String>?=null
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PagerViewHolder {
        val view:View=LayoutInflater.from(context).inflate(R.layout.item_view_pager,parent,false)
        return PagerViewHolder(view)
    }

    override fun getItemCount(): Int {
        list= ArrayList()
        list!!.add("pager1")
        list!!.add("pager2")
        list!!.add("pager3")
        list!!.add("pager4")
        return list!!.size
    }

    override fun onBindViewHolder(holder: PagerViewHolder, position: Int) {
        val colors= arrayOf("#CCFF99","#41F1E5","#8D41F1","#FF99CC")

        holder.tv_view_pager_item.text=list!![position]
        holder.tv_view_pager_item.setBackgroundColor(Color.parseColor(colors[position]))

    }

    inner class PagerViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        var tv_view_pager_item:TextView

        init {
            tv_view_pager_item=itemView.findViewById<TextView>(R.id.tv_view_pager_item)
        }
    }
}